package com.fy.tt.parser;

import com.fy.tt.executor.node.sentence.simpleStmt.*;
import org.antlr.v4.runtime.tree.ParseTree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;

public class Visitor extends V3BaseVisitor{
    public static Map<String, Object> scriptEnvironment = new HashMap<>();
    public static ArrayList<Future> tasks = new ArrayList<>();

    @Override
    public Object visitIntenseStmt(V3Parser.IntenseStmtContext ctx) {


//        IntenseStmt intenseStmt = null;
//        if(ctx.runToolStmt() != null){
//            if(ctx.runToolStmt().notifyStmt() == null){
//                intenseStmt = new IntenseStmt(ctx.runToolStmt(), scriptEnvironment);
//            }else{
//                intenseStmt = new NotifyStmt(ctx.runToolStmt().notifyStmt(), scriptEnvironment);
//            }
//        }
//        intenseStmt.run("");
//        return null;
        return ctx.getChild(0).accept(this);
    }


    @Override
    public Object visitListenStmt(V3Parser.ListenStmtContext ctx) {
        ListenStmt listenStmt = new ListenStmt(ctx, scriptEnvironment);
        Future<?> task = listenStmt.runTask();
        tasks.add(task);
        return null;
    }

    @Override
    public Object visitScheduleStmt(V3Parser.ScheduleStmtContext ctx) {
        ScheduledStmt scheduledStmt = new ScheduledStmt(ctx, scriptEnvironment);
        ScheduledFuture<?> task = scheduledStmt.runTask();
        tasks.add(task);
        return null;
    }

    @Override
    public Object visitAuthoriseStmt(V3Parser.AuthoriseStmtContext ctx){
        AuthoriseStmt authoriseStmt=new AuthoriseStmt(ctx,scriptEnvironment);
        authoriseStmt.run("");
        return null;
    }

    @Override
    public Object visitSetStmt(V3Parser.SetStmtContext ctx) {
        return null;
    }

    @Override
    public List<Future> visit(ParseTree tree) {
        tasks.clear();
        super.visit(tree);
        return tasks;
    }

    @Override
    public Object visitRunToolStmt(V3Parser.RunToolStmtContext ctx ) {
        RunToolStmt runToolStmt = new RunToolStmt(ctx, scriptEnvironment);
        runToolStmt.run("");
        return null;
    }
}
